//
//  Timer+Extension.swift
//  Library_y
//
//  Created by JC on 2023/6/6.
//

import Foundation

public extension Timer {
    
    class func _scheduledTimer (timeInterval: TimeInterval,
                                   repeats: Bool,
                                   completion: @escaping ((_ timer:Timer)->())) -> Timer {
        return Timer.scheduledTimer(timeInterval: timeInterval, target: self, selector: #selector(_completionLoop(timer:)),
               userInfo: completion, repeats: repeats);
    }
    
    @objc class func _completionLoop(timer: Timer) {
        guard let completion = timer.userInfo as? ((Timer) -> ()) else { return; }
        completion(timer)
    }
}
